package com.example.mybatisplusdemo.web.controller;

import com.example.mybatisplusdemo.common.utls.SessionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplusdemo.common.JsonResponse;
import com.example.mybatisplusdemo.service.IAdminService;
import com.example.mybatisplusdemo.model.domain.Admin;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2025-07-04
 * @version v1.0
 */
@RestController
@RequestMapping("/api/admin")
public class AdminController {

    private final Logger logger = LoggerFactory.getLogger(AdminController.class);

    @Autowired
    private IAdminService adminService;

    @GetMapping("getById")
    public JsonResponse getById(Long id) {
        Admin admin = adminService.getById(id);
        return JsonResponse.success(admin);
    }

    @GetMapping("loginByUsername")
    public JsonResponse loginByUsername(Admin admin) {
        Admin loggedInAdmin = adminService.loginByUsername(admin);
        return JsonResponse.success(loggedInAdmin);
    }

    @GetMapping("getInfo")
    public JsonResponse getInfo() {
        Admin admin = SessionUtils.getCurrentAdminInfo();
        return JsonResponse.success(admin);
    }
}
